package no.uib.hplims.tools.columngenerators;

import no.uib.hplims.MyVaadinApplication;
import no.uib.hplims.models.Peptide;

import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Table.ColumnGenerator;
import com.vaadin.ui.themes.BaseTheme;

public class OrderColumnGenerator implements ColumnGenerator{

	private static final long serialVersionUID = 9003339207341798840L;

	public Object generateCell(Table source, Object itemId, Object columnId) {
		final Peptide p = (Peptide) itemId;
		if (p.getBelongsToOrder() != null) {
			Button orderButton = new Button(p
					.getBelongsToOrder().getOrderTitle());
			orderButton.setStyleName(BaseTheme.BUTTON_LINK);
			orderButton
					.addListener(new Button.ClickListener() {
						private static final long serialVersionUID = 8701816885465352359L;

						public void buttonClick(
								ClickEvent event) {
							if (p.getBelongsToOrder() != null) {
								MyVaadinApplication
										.getInstance()
										.getController()
										.showOrder(
												p.getBelongsToOrder());
							}
						}
					});
			return orderButton;
		}
		return new Label("No order connected");
	}

}
